//
//  XBFindTableViewController.m
//  ZhiXinFM
//
//  Created by lanou3g on 15/7/17.
//  Copyright (c) 2015年 YITeam. All rights reserved.
//

#import "XBFindTableViewController.h"
#import "XBFindTableViewCell.h"
#import "AdDataModel.h"
#import "AdScrollView.h"

@interface XBFindTableViewController ()<UINavigationControllerDelegate>


@end

@implementation XBFindTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
//     self.clearsSelectionOnViewWillAppear = YES;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
//     self.navigationItem.rightBarButtonItem =    self.editButtonItem;
    
    
    
    
//    注册(用类来注册)
    [self.tableView registerClass:[XBFindTableViewCell class] forCellReuseIdentifier:@"XBFind"];
    
//    设置navigationBar为透明
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigation_bar_background.png"] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
    
//    设置rightButton按钮(点击进入播放页面)
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"star_unfav@2x"] style:UIBarButtonItemStylePlain target:self action:@selector(pushToMusic)];
    [rightButton setTintColor:[UIColor yellowColor]];
    self.navigationItem.rightBarButtonItem = rightButton;
    
    
}


//点击rightButton进入音乐播放页面
- (void)pushToMusic {
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


//指定行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        return 0;
    }
    if (indexPath.section == 1 && indexPath.row == 0) {
        return 240;
    }
    if (indexPath.section == 2 && indexPath.row == 0) {
        return 240;
    }
    if (indexPath.section == 4 && indexPath.row == 0) {
        return 0;
    }
    
    return 80;
}






//返回区头的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    if (section == 0) {
        
        return 180;
    }
    
    return 50;
}





#pragma mark - Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    if (section == 3) {
        return 6;
    }
    return 1;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
//    static NSString *logo = @"XBFind";
    
    
        
        XBFindTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"XBFind" forIndexPath:indexPath];
        
        
        
        if (!cell) {
            
            cell = [[XBFindTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"XBFind"];
            
        }
        
        cell.imageView.image = [UIImage imageNamed:@"11.jpg"];
        
        return cell;
    
}


//设置轮播图片
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
     
//    设置区头为轮播图片
    if (section == 0) {
        
        /*
        UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
        scrollView.contentSize = CGSizeMake(self.view.frame.size.width*3, 200);
        
        for (int i = 0; i < 4; ++i) {
            
            //        设置视图的frame
            UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width*(i - 1), 0, self.view.frame.size.width, self.view.frame.size.height)];
            //        给视图添加图片
            image.image = [UIImage imageNamed:@"0.jpg"];
            
            //        设置整屏翻动
            scrollView.pagingEnabled = YES;
            
            [scrollView addSubview:image];
            */
        
        AdScrollView *scrollView = [[AdScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 180)];
        
        
        AdDataModel *dataModel = [AdDataModel adDataModelWithImageNameAndAdTitleArray];
        

        scrollView.imageNameArray = dataModel.imageNameArray;
        scrollView.PageControlShowStyle = UIPageControlShowStyleRight;
        scrollView.pageControl.pageIndicatorTintColor = [UIColor whiteColor];
        
        [scrollView setAdTitleArray:dataModel.adTitleArray withShowStyle:AdTitleShowStyleLeft];
        
        scrollView.pageControl.currentPageIndicatorTintColor = [UIColor lightGrayColor];
        [self.view addSubview:scrollView];
        
        return scrollView;
            
        }
    
    
//    设置第一个区头标题"心情"
    if (section == 1) {
        UILabel *sectionTitle1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 60, 60)];
        sectionTitle1.backgroundColor = [UIColor groupTableViewBackgroundColor];
        sectionTitle1.text = @"心情";
        [self.view addSubview:sectionTitle1];
        
        return sectionTitle1;
    }
    
//    设置第二个区头标题"场景"
    if (section == 2) {
        UILabel *sectionTitle2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
        sectionTitle2.backgroundColor = [UIColor groupTableViewBackgroundColor];
        sectionTitle2.text = @"场景";
        [self.view addSubview:sectionTitle2];
        
        return sectionTitle2;
    }
    
//    设置第二个区头标题"主播"
    if (section == 3) {
        UILabel *sectionTitle3 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
        sectionTitle3.backgroundColor = [UIColor groupTableViewBackgroundColor];
        sectionTitle3.text = @"主播";
        [self.view addSubview:sectionTitle3];
        
        return sectionTitle3;
    }
    
    return nil;
    
    }
    

 
//让区头跟cell一起滑动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.tableView)
    {
        CGFloat sectionHeaderHeight = 50;
        if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0)
        {
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y,0, 0, 0);
        } else if (scrollView.contentOffset.y>=sectionHeaderHeight)
        {
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
        }
    }
}








/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
